package org.hongbo.springbootebsapi.service.payment.impl;


import org.hongbo.springbootebsapi.entity.AuthUser;
import org.hongbo.springbootebsapi.entity.payment.PaymentEntity;
import org.hongbo.springbootebsapi.service.payment.IPaymentService;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Repository
@Transactional
public class PaymentServiceImpl implements IPaymentService {

    private static String queryPaymentSql = "select * from cux_payments ";

    @Resource
    private JdbcTemplate jdbcTemplate;

    @Override
    public List<PaymentEntity>  queryPayment(AuthUser user){
        RowMapper<PaymentEntity> rowMapper = new BeanPropertyRowMapper<>(PaymentEntity.class);
        return jdbcTemplate.query(queryPaymentSql, rowMapper);
    }

    @Override
    public PaymentEntity findPayment(String paymentId, AuthUser user){
        String  sql = new StringBuilder(queryPaymentSql).append(" where payment_id = ?").toString();
        Object[] objects = new Object[]{paymentId};
        RowMapper<PaymentEntity> rowMapper = new BeanPropertyRowMapper<>(PaymentEntity.class);
        return jdbcTemplate.queryForObject(sql, objects, rowMapper);
    }


}
